package mysql

import (
	"gorm.io/gorm"
	"time"
)

type TimeModel struct {
	Addtime int64 `gorm:"addtime" json:"addtime"`
	Uptime  int64 `gorm:"uptime" json:"uptime"`
}

func (c *TimeModel) BeforeCreate(tx *gorm.DB) error {
	c.Addtime = time.Now().Unix()
	c.Uptime = time.Now().Unix()
	return nil
}

func (c *TimeModel) BeforeUpdate(tx *gorm.DB) error {
	tx.Statement.SetColumn("uptime", time.Now().Unix())
	return nil
}
